﻿namespace Crocodile.CsharpLanguage.Tree
{
    public class CsAssignment : CsStatement
    {
        public string VarName;
        public CsExpression Expression;


        public override string[] Text
        {
            get 
            { 
                string[] expr = Expression.Text;
                int n = expr.Length;
                switch (n)
                {
                    case 0:
                        return new[] { VarName + ';' };

                    case 1:
                        return new[] { VarName + " = " + expr[0] + ';' };

                    default:
                        string[] stmt = new string[n+1];
                        stmt[0] = VarName + " = ";
                        for (int i = 1; i < n; i++)
                            stmt[i] = '\t' + expr[i-1];
                        stmt[n] = '\t' + expr[n-1] + ';';
                        return stmt;
                }
            }
        }
    }
}
